import Vue from 'vue'
import 'normalize.css/normalize.css'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App'

import store from './store'

import router from './router'
import './router/permission'

// 注册svg
import '@/icons'

Vue.use(ElementUI)

Vue.config.productionTip = false


// vue实例化
new Vue({
  el: '#app',
  router,
  store,

  render: h => h(App),
  created() {
    // 在应用初始化时检查 Vuex 中是否有路由信息
    const storedRoutes = localStorage.getItem('routes')

    if (storedRoutes) {
      // 将本地存储的路由信息转换为路由数组
      const routes = JSON.parse(storedRoutes)

      // 将路由信息存储到 Vuex 中
      this.$store.dispatch('setRoutes', routes)

      // 动态添加路由
      this.$router.addRoutes(routes)
    }
  }
}).$mount('#app')
